$(function() {
    $('#cat-list').uiTreeTable();

    $('.cate-sort').change(function() {
        var me = $(this), sort = me.val(), cid = me.attr('rel');
        if(/^[0-9]{1,3}$/.test(sort)) {
            me.addClass('ico-loading-14r').attr('disabled', 'disabled');
            $.ajax({
                url : './?Ctlr=SetCateSort&cid=' + cid + '&sort=' + sort,
                success : function(data) {
                    if(!data.success) {
                        alert(data.msg);
                    }
                    me.removeClass('ico-loading-14r').removeAttr('disabled');
                }
            });
        } else {
            me.focus();
            alert('只能是数值');
        }
    });
    $('i.display').click(function() {
        if(!confirm('你确定要改变栏目在导航方式吗?')) {
            return false;
        }
        var me = $(this), cid = me.parents('tr').attr('id').replace('c-', '');
        var display = me.hasClass('icon-eye-open') ? 0 : 1;
        me.addClass('icon-loading-14');
        if(display) {//点击不显示
            me.removeClass('icon-eye-close');
        } else {
            me.removeClass('icon-eye-open');
        }
        $.ajax({
            url : './?Ctlr=SetCateDisplay&cid=' + cid + '&display=' + display,
            success : function(data) {
                if(data.success) {
                    if(display) {
                        me.addClass('icon-eye-open');
                    } else {
                        me.addClass('icon-eye-close');
                    }
                } else {
                    alert(data.msg);
                }
                me.removeClass('icon-loading-14');
            }
        });
        return false;
    });
    $('.publish').click(function(){
    	var me = $(this),href = me.attr('href'),title=me.attr('data-content'),id=me.attr('id');
    	openTab(href,id,'发布：'+title,'icon_editor');
    	return false;
    });
});
